﻿#include "plugin_manager.h"

PluginManager &PluginManager::instance()
{
    static PluginManager instance;
    return instance;
}

void PluginManager::loadPlugins(const QString &path)
{
    QDir pluginsDir(path);
    if (!pluginsDir.exists()) {
        qWarning() << "插件目录不存在:" << path;
        return;
    }

    m_plugins.clear();

    for (const QString &fileName : pluginsDir.entryList(QDir::Files)) {
        QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
        QObject *plugin = loader.instance();
        if (plugin) {
            IAlgorithmPlugin *alg = qobject_cast<IAlgorithmPlugin *>(plugin);
            if (alg) {
                m_plugins.append(alg);
                qDebug() << "加载插件:" << alg->name();
            }
        }
    }
}

const QList<IAlgorithmPlugin *> &PluginManager::plugins() const
{
    return m_plugins;
}
